/**
 * @param {number} n
 * @return {boolean}
 */
var isHappy = function(n) {
    let set = new Set()
    let num = n
   
    while(true){
        
        if(set.has(num)){
            return false
        }
        if(num == 1){
            return true
        }
        let count = 0
        for (const iterator of String(num)) {
            count += Number(iterator)*Number(iterator)
        }
        console.log(count)
        set.add(num)
        num = count

    }
};
console.log(isHappy(2));
